package cn.edu.ctbu.demo.api;

import cn.edu.ctbu.demo.entity.Student;
import cn.edu.ctbu.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/student")
public class StudentApiController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/list")
    public List<Student> findAll(){
        List<Student> students = studentService.getAll();
        return students;
    }

//    @GetMapping("/{id}")
//    public Student findById (@PathVariable int id){
//        Student student = studentService.findById(id);
//        return student;
//    }

    @PostMapping("/add")
    public Student add(Student student){

        return studentService.add(student);
    }

    @PutMapping("/gengxin")
    public Student gengxin(Student student){

        return   studentService.gengxin(student);
    }

    @DeleteMapping("/shanchu/{id}")
    public void shanchu(@PathVariable Integer id){

        studentService.shanchu(id);
    }
}